home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWExcLib / FWExcDef.h next >
Encoding:
Text File  |  1996-09-17  |  12.7 KB  |  411 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWExcDef.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWEXCDEF_H
  11. #define FWEXCDEF_H
  12.  
  13. #ifndef FWSTDDEF_H
  14. #include "FWStdDef.h"
  15. #endif
  16.  
  17. #ifndef FWCLAINF_H
  18. #include "FWClaInf.h"
  19. #endif
  20.  
  21. #ifndef FWEXCEPT_H
  22. #include "FWExcept.h"
  23. #endif
  24.  
  25. #ifndef FWDEBUG_H
  26. #include "FWDebug.h"
  27. #endif
  28.  
  29. #include <setjmp.h>
  30.  
  31. // The _FW_AUTO_PROTO macros are only expanded for Windows! %%% SFU %%%
  32.  
  33. #ifdef FW_BUILD_WIN
  34. #define _FW_AUTO_PROTO1 extern void FW_PrivStaticDestroyer(className* self); /* KVV */ 
  35. #define _FW_AUTO_PROTO2 extern void FW_PrivStaticDestroyer(className< Type >* self);
  36. #define _FW_AUTO_PROTO3 extern void FW_PrivStaticDestroyer(className< Type1, Type2 >* self);
  37. #else
  38. #define _FW_AUTO_PROTO1
  39. #define _FW_AUTO_PROTO2
  40. #define _FW_AUTO_PROTO3
  41. #endif
  42.  
  43. #ifdef FW_ANSI_TEMPLATE_INSTANTIATION
  44. // Unfortunately specializing a template function is compiler dependent.
  45. // Metrowerks wants all definitions to be present when it sees the instantiation, and 
  46. // will give a compile error for definitions not yet seen, even if the occur later
  47. // in the translation unit.
  48. // Symantec does the opposite.  If a specialized member function is given before
  49. // the template instantiation, it is (quietly) clobbered when the instantiation happens.
  50. // The result is missing definitions, unless the specializations come after the instantiation.
  51.     #ifdef __MWERKS__
  52.     #define _FW_INSTANTIATE_BEFORE1(className, Type)
  53.     #define _FW_INSTANTIATE_BEFORE2(className, Type1, Type2)
  54.     #define _FW_INSTANTIATE_AFTER1(className, Type) template class className<Type>;
  55.     #define _FW_INSTANTIATE_AFTER2(className, Type1, Type2) template class className<Type1, Type2>;
  56.     #endif
  57.     #ifdef __SC__
  58.     #define _FW_INSTANTIATE_BEFORE1(className, Type) template class className<Type>;
  59.     #define _FW_INSTANTIATE_BEFORE2(className, Type1, Type2) template class className<Type1, Type2>;
  60.     #define _FW_INSTANTIATE_AFTER1(className, Type)
  61.     #define _FW_INSTANTIATE_AFTER2(className, Type1, Type2)
  62.     #endif
  63. #else
  64.     #define _FW_INSTANTIATE_BEFORE1(className, Type)
  65.     #define _FW_INSTANTIATE_BEFORE2(className, Type1, Type2)
  66.     #define _FW_INSTANTIATE_AFTER1(className, Type)
  67.     #define _FW_INSTANTIATE_AFTER2(className, Type1, Type2)
  68. #endif
  69.  
  70. #ifdef FW_NATIVE_EXCEPTIONS
  71.  
  72. // --------------- Native exceptions
  73.  
  74.     #define FW_TRY \
  75.         try
  76.  
  77.     #define FW_CATCH_BEGIN
  78.     
  79.     #define FW_CATCH(class, error) \
  80.         catch(class error)
  81.  
  82.     #define FW_CATCH_REFERENCE(class, error) \
  83.         catch(class& error)
  84.  
  85.     #define FW_CATCH_NO_INSTANCE(class)    \
  86.         catch(class)
  87.  
  88.     #define FW_CATCH_EVERYTHING()    \
  89.         catch(...)
  90.  
  91.     #define FW_CATCH_END
  92.  
  93.     #define FW_THROW(error)             throw error
  94.     #define FW_THROW_SAME()                throw
  95.  
  96.     #define FW_NEW(class, args)            new class##args
  97.  
  98.     #define FW_VOLATILE(variable)
  99.     
  100.     #define FW_END_CONSTRUCTOR
  101.     #define FW_START_DESTRUCTOR
  102.     #define FW_DECLARE_AUTO(className)
  103.     #define FW_DEFINE_AUTO(className)
  104.     #define FW_DEFINE_AUTO_TEMPLATE(className, Type) template class className<Type>;
  105.     #define FW_DEFINE_AUTO_TEMPLATE2(className, Type1, Type2) template class className<Type1, Type2>;
  106.     #define FW_DECLARE_EXCEPTION(className)    FW_DECLARE_CLASS
  107.     #define FW_DEFINE_EXCEPTION(className)
  108.     
  109. #else
  110.  
  111. // --------------- Emulated exceptions
  112.  
  113.     #define FW_TRY \
  114.         { \
  115.             jmp_buf    __jumpBuffer; \
  116.             if(setjmp(__jumpBuffer) == 0) \
  117.             { \
  118.                 FW_CPrivTryBlockContext __context(__jumpBuffer, longjmp);
  119.     
  120.     #define FW_CATCH_BEGIN \
  121.             } \
  122.             else \
  123.             { \
  124.                 if (0) \
  125.                 {
  126.     
  127.     #define FW_CATCH(aClass, error) \
  128.                 } \
  129.                 else if (FW_PrivCanCatchThisException(FW_PrivStaticGetClassInfo((aClass*)0))) \
  130.                 { \
  131.                     aClass error = * (aClass*) FW_PrivGetThrownException(); \
  132.                     FW_PrivCaughtException(&error, sizeof(aClass), FW_PrivStaticGetClassInfo((aClass*)0), FW_PrivGetDestroyProc(&error), FW_PrivGetCloneProc(&error));
  133.     
  134.     #define FW_CATCH_REFERENCE(aClass, error) \
  135.                 } \
  136.                 else if (FW_PrivCanCatchThisException(FW_PrivStaticGetClassInfo((aClass*)0))) \
  137.                 { \
  138.                     aClass & error = *(aClass*) FW_PrivGetThrownException(); \
  139.                     FW_PrivCaughtReferenceException();
  140.     
  141.     #define FW_CATCH_NO_INSTANCE(aClass) \
  142.                 } \
  143.                 else if (FW_PrivCanCatchThisException(FW_PrivStaticGetClassInfo((aClass*)0))) \
  144.                 { \
  145.                     FW_PrivCaughtNoInstanceException();
  146.     
  147.     #define FW_CATCH_EVERYTHING() \
  148.                 } \
  149.                 else if (1) \
  150.                 { \
  151.                     FW_PrivCaughtEverythingException();
  152.     
  153.     #define FW_CATCH_END \
  154.                 } \
  155.                 else \
  156.                 { \
  157.                     FW_PrivKeepThrowing(); \
  158.                 } \
  159.             FW_PrivCatchCleanup(); \
  160.             } \
  161.         }
  162.     
  163.     #define FW_THROW(error) \
  164.         FW_PrivThrowException(error)
  165.     
  166.     #define FW_THROW_SAME() \
  167.         FW_PrivThrowSame()
  168.     
  169.     #define FW_NEW(class, args) (class*) \
  170.         ( \
  171.             new(FW_CPrivWatcher(FW_PrivGetDeleteProc((const class*)0))) class##args, \
  172.             FW_PrivWatcher_Pop() \
  173.         )
  174.     
  175.     #define FW_VOLATILE(variable) FW_gPrivVolatileKludge = &variable
  176.     
  177.     //----------------------------------------------------------------------------------------
  178.     // macro FW_DEFINE_AUTO
  179.     //
  180.     // This macro must be invoked in the .cpp file that contains all of the definitions of 
  181.     // the constructors of an auto-destruct class.
  182.     //----------------------------------------------------------------------------------------
  183.     
  184.     #ifdef FW_DEBUG
  185.         #define _FW_DECLARE_AUTO_NAME(className) \
  186.             friend char* FW_PrivGetAutoName(const className*);
  187.         #define _FW_DEFINE_AUTO_NAME(className) \
  188.             char* FW_PrivGetAutoName(const className*) \
  189.             { \
  190.                 return #className; \
  191.             }
  192.         #define _FW_DEFINE_AUTO_NAME_TEMPLATE(className, Type) \
  193.             char* FW_PrivGetAutoName(const className< Type >*) \
  194.             { \
  195.                 return #className#Type; \
  196.             }
  197.         #define _FW_DEFINE_AUTO_NAME_TEMPLATE2(className, Type1, Type2) \
  198.             char* FW_PrivGetAutoName(const className< Type1, Type2 >*) \
  199.             { \
  200.                 return #className#Type1#Type2; \
  201.             }
  202.     #else
  203.         #define _FW_DECLARE_AUTO_NAME(className)
  204.         #define _FW_DEFINE_AUTO_NAME(className)
  205.         #define _FW_DEFINE_AUTO_NAME_TEMPLATE(className, Type)
  206.         #define _FW_DEFINE_AUTO_NAME_TEMPLATE2(className, Type1, Type2)
  207.     #endif
  208.     
  209.     #define FW_DECLARE_AUTO(className) \
  210.         _FW_DECLARE_AUTO_NAME(className) \
  211.         friend FW_PrivDestroyProc FW_PrivGetDestroyProc(const className*); \
  212.         friend FW_PrivDeleteProc FW_PrivGetDeleteProc(const className*); \
  213.         void* operator new(size_t size, const FW_CPrivWatcher &w); \
  214.         void operator delete(void* p); \
  215.         private: \
  216.             void* operator new(size_t); \
  217.         public:
  218.     
  219.     #define FW_DEFINE_AUTO(className) \
  220.         _FW_DEFINE_AUTO_NAME(className) \
  221.         _FW_AUTO_PROTO1 \
  222.         extern FW_PrivDestroyProc FW_PrivGetDestroyProc(const className*); \
  223.         extern FW_PrivDeleteProc FW_PrivGetDeleteProc(const className*); \
  224.         extern "C" \
  225.         { \
  226.             static void FW_PrivStaticDestroyer##className(void* self) \
  227.             { \
  228.                 FW_PrivStaticDestroyer((className*) self); \
  229.             } \
  230.             static void FW_PrivStaticDeleter##className(void* p) \
  231.             { \
  232.                 className::operator delete(p); \
  233.             } \
  234.         } \
  235.         FW_PrivDestroyProc FW_PrivGetDestroyProc(const className*) \
  236.         { \
  237.             return FW_PrivStaticDestroyer##className; \
  238.         } \
  239.         FW_PrivDeleteProc FW_PrivGetDeleteProc(const className*) \
  240.         { \
  241.             return FW_PrivStaticDeleter##className; \
  242.         } \
  243.         void* className::operator new(size_t size, const FW_CPrivWatcher &w) \
  244.         { \
  245.             return FW_PrivWatcher_New(FW_PrimitiveAllocateBlock(size), size, (FW_SPrivWatcher*) &w); \
  246.         } \
  247.         void className::operator delete(void* p) \
  248.         { \
  249.             FW_PrimitiveFreeBlock(p); \
  250.         } \
  251.         void* className::operator new(size_t) \
  252.         { \
  253.             FW_ASSERT(("Bad call to hidden operator new!", false)); \
  254.             return 0; \
  255.         } \
  256.     
  257.     #define FW_DEFINE_AUTO_TEMPLATE(className, Type) \
  258.         extern FW_PrivDestroyProc FW_PrivGetDestroyProc(const className<Type>*); \
  259.         extern FW_PrivDeleteProc FW_PrivGetDeleteProc(const className<Type>*); \
  260.         _FW_INSTANTIATE_BEFORE1(className, Type) \
  261.         void* className<Type>::operator new(size_t size, const FW_CPrivWatcher &w) \
  262.         { \
  263.             return FW_PrivWatcher_New(FW_PrimitiveAllocateBlock(size), size, (FW_SPrivWatcher*) &w); \
  264.         } \
  265.         void className<Type>::operator delete(void* p) \
  266.         { \
  267.             FW_PrimitiveFreeBlock(p); \
  268.         } \
  269.         void* className<Type>::operator new(size_t) \
  270.         { \
  271.             FW_ASSERT(("Bad call to hidden operator new!", false)); \
  272.             return 0; \
  273.         } \
  274.         _FW_INSTANTIATE_AFTER1(className, Type) \
  275.         _FW_DEFINE_AUTO_NAME_TEMPLATE(className, Type) \
  276.         _FW_AUTO_PROTO2 \
  277.         extern "C" \
  278.         { \
  279.             static void FW_PrivStaticDestroyer##className##Type(void* self) \
  280.             { \
  281.                 FW_PrivStaticDestroyer((className< Type >*) self); \
  282.             } \
  283.             static void FW_PrivStaticDeleter##className##Type(void* p) \
  284.             { \
  285.                 className< Type >::operator delete(p); \
  286.             } \
  287.         } \
  288.         FW_PrivDestroyProc FW_PrivGetDestroyProc(const className<Type>*) \
  289.         { \
  290.             return FW_PrivStaticDestroyer##className##Type; \
  291.         } \
  292.         FW_PrivDeleteProc FW_PrivGetDeleteProc(const className<Type>*) \
  293.         { \
  294.             return FW_PrivStaticDeleter##className##Type; \
  295.         }
  296.         
  297.     #define FW_DEFINE_AUTO_TEMPLATE2(className, Type1, Type2) \
  298.         _FW_DEFINE_AUTO_NAME_TEMPLATE2(className, Type1, Type2) \
  299.         _FW_AUTO_PROTO3 \
  300.         extern FW_PrivDestroyProc FW_PrivGetDestroyProc(const className<Type1, Type2>*); \
  301.         extern FW_PrivDeleteProc FW_PrivGetDeleteProc(const className<Type1, Type2>*); \
  302.         _FW_INSTANTIATE_BEFORE2(className, Type1, Type2) \
  303.         void* className< Type1, Type2 >::operator new(size_t size, const FW_CPrivWatcher &w) \
  304.         { \
  305.             return FW_PrivWatcher_New(FW_PrimitiveAllocateBlock(size), size, (FW_SPrivWatcher*) &w); \
  306.         } \
  307.         void className< Type1, Type2 >::operator delete(void* p) \
  308.         { \
  309.             FW_PrimitiveFreeBlock(p); \
  310.         } \
  311.         void* className< Type1, Type2 >::operator new(size_t) \
  312.         { \
  313.             FW_ASSERT(("Bad call to hidden operator new!", false)); \
  314.             return 0; \
  315.         } \
  316.         _FW_INSTANTIATE_AFTER2(className, Type1, Type2) \
  317.         extern "C" \
  318.         { \
  319.             static void FW_PrivStaticDestroyer##className##Type1##Type2(void* self) \
  320.             { \
  321.                 FW_PrivStaticDestroyer((className< Type1, Type2 >*) self); \
  322.             } \
  323.             static void FW_PrivStaticDeleter##className##Type1##Type2(void* p) \
  324.             { \
  325.                 className< Type1, Type2 >::operator delete(p); \
  326.             } \
  327.         } \
  328.         FW_PrivDestroyProc FW_PrivGetDestroyProc(const className<Type1, Type2>*) \
  329.         { \
  330.             return FW_PrivStaticDestroyer##className##Type1##Type2; \
  331.         } \
  332.         FW_PrivDeleteProc FW_PrivGetDeleteProc(const className<Type1, Type2>*) \
  333.         { \
  334.             return FW_PrivStaticDeleter##className##Type1##Type2; \
  335.         } \
  336.     
  337.     //----------------------------------------------------------------------------------------
  338.     // macro FW_END_CONSTRUCTOR
  339.     //
  340.     // This macro must be invoked at the end of every constructor of an auto-destruct class
  341.     //----------------------------------------------------------------------------------------
  342.     
  343.     #ifdef FW_DEBUG
  344.         #define FW_END_CONSTRUCTOR \
  345.             FW_AutoConstructed(this, sizeof(*this), FW_PrivGetDestroyProc(this), FW_PrivGetAutoName(this));
  346.     #else
  347.         #define FW_END_CONSTRUCTOR \
  348.             FW_AutoConstructed(this, sizeof(*this), FW_PrivGetDestroyProc(this));
  349.     #endif
  350.     
  351.     //----------------------------------------------------------------------------------------
  352.     // macro FW_START_DESTRUCTOR
  353.     //
  354.     // This macro must be invoked at the beginning of the destructor of an auto-destruct class
  355.     //----------------------------------------------------------------------------------------
  356.     
  357.     #ifdef FW_DEBUG
  358.         #define FW_START_DESTRUCTOR \
  359.             FW_AutoDestructed(this, FW_PrivGetDestroyProc(this), FW_PrivGetAutoName(this));
  360.     #else
  361.         #define FW_START_DESTRUCTOR \
  362.             FW_AutoDestructed(this);
  363.     #endif
  364.         
  365.     //----------------------------------------------------------------------------------------
  366.     // macro FW_DEFINE_EXCEPTION
  367.     //
  368.     // This macro must be invoked in the .cpp file that contains all of the definitions of 
  369.     // the constructors of an exception class.
  370.     //----------------------------------------------------------------------------------------
  371.     
  372.     #define FW_DECLARE_EXCEPTION(className) \
  373.         FW_DECLARE_CLASS \
  374.         friend FW_PrivCloneProc FW_PrivGetCloneProc(const className*); \
  375.         friend FW_PrivDestroyProc FW_PrivGetDestroyProc(const className*);
  376.     
  377.     #define FW_DEFINE_EXCEPTION(className) \
  378.         _FW_AUTO_PROTO1 \
  379.         extern "C" \
  380.         { \
  381.             static void FW_PrivStaticDestroyer##className(void* self) \
  382.             { \
  383.                 FW_PrivStaticDestroyer((className*) self); \
  384.             } \
  385.             static void FW_PrivStaticCloner##className(void* self, void* destination, size_t destSize) \
  386.             { \
  387.                 FW_PrivClone((className*) self, destination, destSize); \
  388.             } \
  389.         } \
  390.         FW_PrivDestroyProc FW_PrivGetDestroyProc(const className*) \
  391.         { \
  392.             return FW_PrivStaticDestroyer##className; \
  393.         } \
  394.         FW_PrivCloneProc FW_PrivGetCloneProc(const className*) \
  395.         { \
  396.             return FW_PrivStaticCloner##className; \
  397.         }
  398.     
  399.     
  400. #endif
  401.     
  402. #if 0
  403. #define FW_DECLARE_THROW_POINT(NAME) FW_CExceptionThrowPoint FW_g##NAME##ThrowPoint (#NAME)
  404. #define FW_CHECK_THROW_POINT(NAME)     FW_g##NAME##ThrowPoint.Check ()
  405. #else
  406. #define FW_DECLARE_THROW_POINT(NAME) 
  407. #define FW_CHECK_THROW_POINT(NAME)     
  408. #endif
  409.  
  410. #endif
  411.